/*    */ package com.zimbra.cs.service.admin;
/*    */ 
/*    */ import com.zimbra.common.account.Key.ServerBy;
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.AdminConstants;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.cs.account.Provisioning;
/*    */ import com.zimbra.cs.account.Server;
/*    */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*    */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*    */ import com.zimbra.cs.rmgmt.RemoteMailQueue;
/*    */ import com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAction;
/*    */ import com.zimbra.cs.rmgmt.RemoteMailQueue.QueueAttr;
/*    */ import com.zimbra.cs.rmgmt.RemoteMailQueue.SearchResult;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.List;
/*    */ import java.util.Map;
/*    */ import org.apache.lucene.search.Query;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class MailQueueAction
/*    */   extends AdminDocumentHandler
/*    */ {
/*    */   public Element handle(Element request, Map<String, Object> context)
/*    */     throws ServiceException
/*    */   {
/* 42 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 43 */     Provisioning prov = Provisioning.getInstance();
/*    */     
/* 45 */     Element serverElem = request.getElement("server");
/* 46 */     String serverName = serverElem.getAttribute("name");
/*    */     
/* 48 */     Server server = prov.get(Key.ServerBy.name, serverName);
/* 49 */     if (server == null) {
/* 50 */       throw ServiceException.INVALID_REQUEST("server with name " + serverName + " could not be found", null);
/*    */     }
/*    */     
/* 53 */     checkRight(zsc, context, server, Rights.Admin.R_manageMailQueue);
/*    */     
/* 55 */     Element queueElem = serverElem.getElement("queue");
/* 56 */     String queueName = queueElem.getAttribute("name");
/*    */     
/* 58 */     RemoteMailQueue rmq = RemoteMailQueue.getRemoteMailQueue(server, queueName, false);
/*    */     
/* 60 */     Element actionElem = queueElem.getElement("action");
/* 61 */     String op = actionElem.getAttribute("op");
/* 62 */     RemoteMailQueue.QueueAction action = RemoteMailQueue.QueueAction.valueOf(op);
/* 63 */     if (action == null) {
/* 64 */       throw ServiceException.INVALID_REQUEST("bad op:" + op, null);
/*    */     }
/* 66 */     String by = actionElem.getAttribute("by");
/*    */     String[] ids;
/* 68 */     if (by.equals("id")) {
/* 69 */       ids = actionElem.getText().split(","); } else { String[] ids;
/* 70 */       int i; if (by.equals("query")) {
/* 71 */         Element queryElem = actionElem.getElement("query");
/* 72 */         Query query = GetMailQueue.buildLuceneQuery(queryElem);
/* 73 */         RemoteMailQueue.SearchResult sr = rmq.search(query, 0, Integer.MAX_VALUE);
/* 74 */         ids = new String[sr.qitems.size()];
/* 75 */         i = 0;
/* 76 */         for (Map<RemoteMailQueue.QueueAttr, String> qitem : sr.qitems) {
/* 77 */           ids[(i++)] = ((String)qitem.get(RemoteMailQueue.QueueAttr.id));
/*    */         }
/*    */       } else {
/* 80 */         throw ServiceException.INVALID_REQUEST("bad by: " + by, null);
/*    */       } }
/*    */     String[] ids;
/* 83 */     rmq.action(server, action, ids);
/*    */     
/* 85 */     Element response = zsc.createElement(AdminConstants.MAIL_QUEUE_ACTION_RESPONSE);
/* 86 */     return response;
/*    */   }
/*    */   
/*    */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*    */   {
/* 91 */     relatedRights.add(Rights.Admin.R_manageMailQueue);
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/MailQueueAction.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */